package dk.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ReturnData.ResponseData;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.beans.Examlist;


import dk.service.ApiService;

@RestController
@RequestMapping("api")
public class ExamController {
	@Autowired
	ApiService apiservice;

@PostMapping("/GetExamList")
public ResponseData GetExamList() {
	return apiservice.GetExamList();
}
@PostMapping("/AddExamList")
public ResponseData AddExamList(
		String answer,
		Integer difficulty,
		String optiona,
		String optionb,
		String optionc,
		String optiond,
		String parse,
		Integer scorce,
		Integer subjectid,
		String title,
		Integer type
		) {
	System.out.println(answer);
	System.out.println("AddExamList");
	
	return apiservice.AddExamList(
			/*examlist.getAnswer(),
			examlist.getDifficulty(),
			examlist.getOptiona(),
			examlist.getOptionb(),
			examlist.getOptionc(),
			examlist.getOptiond(),
			examlist.getParse(),
			examlist.getScorce(),
			examlist.getSubjectid(),
			examlist.getTitle(),
			examlist.getType()*/
			answer,
			difficulty,
			optiona,
			optionb,
			optionc,
			optiond,
			parse,
			scorce,
			subjectid,
			title,
			type
			);
}
//根据学科获取信息
@PostMapping("/SearchExamlistBySubjectName")
public  ResponseData SearchExamlistBySubjectName(String subjectname) {
	return apiservice.SearchExamlistBySubjectID(subjectname);
	
}
//根据题目获取eaxmlist
@PostMapping("/SearchExamListByExamListTitle")
public  ResponseData SearchExamListByExamListTitle(String ExamListTitle) {
	return apiservice.SearchExamListByExamListTitle(ExamListTitle);
	
}
//题目信息的分页查询
@PostMapping("/SearchExamListByPage")
public  ResponseData  SearchExamListByPage(Integer pagenum,Integer count) {
	return apiservice.SearchExamListByPage(pagenum,count);
}
//通过id查询
@PostMapping("GetExamListById")
public  ResponseData GetExamListByid(Integer id) {
	return apiservice.GetExamListByid(id);
}
//根据id进行examlist的更新操作
@PostMapping("/UpdateExamListById")
public ResponseData UpdateExamListById(
		Integer id,
		String answer,
		Integer difficulty,
		String optiona,
		String optionb,
		String optionc,
		String optiond,
		String parse,
		Integer scorce,
		Integer subjectid,
		String title,
		Integer type
		) {
	System.out.println("UpdateExamList");
	
	return apiservice.UpdateExamListById(
			/*examlist.getAnswer(),
			examlist.getDifficulty(),
			examlist.getOptiona(),
			examlist.getOptionb(),
			examlist.getOptionc(),
			examlist.getOptiond(),
			examlist.getParse(),
			examlist.getScorce(),
			examlist.getSubjectid(),
			examlist.getTitle(),
			examlist.getType()*/
			id,
			answer,
			difficulty,
			optiona,
			optionb,
			optionc,
			optiond,
			parse,
			scorce,
			subjectid,
			title,
			type
			);
}
@PostMapping("DeleteExamListByid")
public ResponseData DeleteExamListByid(Integer id) {
	return apiservice.DeleteExamListByid(id);
}
@PostMapping("GetExamListEchart")
public ResponseData GetExamListEchart() {
	return apiservice.GetExamListEchart();
}
@PostMapping("BatchAddOptionExamList")
//需要进行服务解码
public ResponseData BatchAddOptionExamList(@RequestBody String examliststr) throws UnsupportedEncodingException {
	examliststr = URLDecoder.decode(examliststr, "utf-8");
	examliststr = examliststr.substring(0, examliststr.length()-1);
	System.out.println(examliststr);
	//return null;
	return apiservice.BatchAddOptionExamList(examliststr);
}
@PostMapping("BatchAddShortAnswerExamList")
//需要进行服务解码
public ResponseData BatchAddShortAnswerExamList(@RequestBody String examliststr) throws UnsupportedEncodingException {
	examliststr = URLDecoder.decode(examliststr, "utf-8");
	examliststr = examliststr.substring(0, examliststr.length()-1);
	System.out.println(examliststr);
	//return null;
	return apiservice.BatchAddShortAnswerExamList(examliststr);
}
@PostMapping("GenerateExamList")
public ResponseData GenerateExamList(Integer TotalScore,Integer	OptionNum,Integer ShortAnswerNum) {
	return apiservice.GenerateExamList(TotalScore,OptionNum,ShortAnswerNum);
	
}


}
